<!DOCTYPE html>
<html>
  <head>
    <title>2.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
        <style>#video {display: block;margin:1em auto;width:180px;height:180px;}</style>    
    <video id="video" autoplay></video>  
    <script>  
        window.addEventListener("DOMContentLoaded", function () {  
            var video = document.getElementById("video"), canvas, context;  
            try {  
                canvas = document.createElement("canvas");  
                context = canvas.getContext("2d");  
            } catch (e) { alert("not support canvas!"); return; }  
            navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;  
      
      
            if (navigator.getUserMedia)  
                navigator.getUserMedia(  
                    { "video": true },  
                    function (stream) {  
                        if (video.mozSrcObject !== undefined)video.mozSrcObject = stream;  
                        else video.src = ((window.URL || window.webkitURL || window.mozURL || window.msURL) && window.URL.createObjectURL(stream)) || stream;                 
                        video.play();  
                    },  
                    function (error) {  
                        //if(error.PERMISSION_DENIED)console.log("用户拒绝了浏览器请求媒体的权限",error.code);  
                        //if(error.NOT_SUPPORTED_ERROR)console.log("当前浏览器不支持拍照功能",error.code);  
                        //if(error.MANDATORY_UNSATISFIED_ERROR)console.log("指定的媒体类型未接收到媒体流",error.code);  
                        alert("Video capture error: " + error.code);  
                    }  
                );  
            else alert("Native device media streaming (getUserMedia) not supported in this browser");  
             
      
      
            setInterval(function () {  
                context.drawImage(video, 0, 0, canvas.width = video.videoWidth, canvas.height = video.videoHeight);  
                $.post('/Home/QRcodeDecode', { "img": canvas.toDataURL().substr(22) }, function (data, status) {  
                    if (status == "success" && data != "no")location.href = "/Home/Result/" + data;                 
                }, "text");  
            }, 500);  
      
      
        }, false);  
     </script>   
  </body>
</html>
